
"""
@FileName：tk_learning.py\n
@Description：\n
@Author：锦沐Python\n
@Time：2024/8/2 22:08\n
"""
#!/usr/bin/env python
# -*- coding: utf-8 -*-


from tkinter import *
from tkinter import ttk
import ctypes
# 在Windows操作系统中，AppUserModelID 是一种标识符，用于唯一标识应用程序。这个标识符可以影响到应用程序在任务栏、开始菜单和其他位置的显示方式和分组方式
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('passlink_tk')


if __name__ == "__main__":
    main_window = Tk()
    # 设置了主窗口的宽度为600像素，高度为400像素，并将窗口的左上角位置定位在屏幕上的坐标(200, 200)处
    # 设置窗口透明度
    main_window.wm_attributes('-alpha', 1)
    main_window.geometry("600x400+200+200")
    main_window.title("锦沐的小程序")
    main_window.configure(background="#5AA7EA", pady=20, padx=20)
    main_window.iconbitmap("./icon.ico")
    # 设置窗口的最小宽度和最小高度
    main_window.minsize(500, 300)
    # 设置窗口的最大宽度和最大高度
    main_window.maxsize(900, 800)

    # 创建 Frame 部件并设置参数
    # frame = Frame(master=main_window, bg="yellow", width=400, height=500)
    # frame.pack_propagate(False)
    # frame.pack()

    # 创建 Label 部件并将其放置在 Frame 内
    # label1 = Label(master=frame, text="Hello1")
    # label1.pack(anchor="center")
    #
    # label2 = Label(master=frame, text="Hello2", bg="#5DE2E7")
    # label2.pack()
    #
    # label3 = Label(master=frame, text="Hello3", bg="#5DE2E7", fg="red")
    # label3.pack()
    #
    # label4 = Label(master=frame, text="Hello4", bg="#5DE2E7", fg="red", font=("Arial", 20))
    # label4.pack()
    # #
    # label5 = Label(master=frame, text="Hello5")
    # label5.pack(padx=(100, 20))
    # label6 = Label(master=frame, text="Hello6")
    # label6.pack(pady=(20, 50))
    # label7 = Label(master=frame, text="Hello7")
    # label7.pack(padx=50)
    # label8 = Label(master=frame, text="Hello8")
    # label8.pack(pady=20)
    # label9 = Label(master=frame, text="Hello9")
    # label9.pack(ipadx=20)
    # label10 = Label(master=frame, text="Hello10")
    # label10.pack(ipady=20)
    #
    # label11 = Label(master=frame, text="Hello11")
    # label11.pack(side="right")
    # label12 = Label(master=frame, text="Hello12")
    # label12.pack(side="left")
    # label13 = Label(master=frame, text="Hello13")
    # label13.pack(fill="both")
    # label14 = Label(master=frame, text="Hello14")
    # label14.pack(fill="x")
    # label15 = Label(master=frame, text="Hello15")
    # label15.pack(expand=True)
    # label16 = Label(master=frame, text="Hello16")
    # label16.pack(anchor="se")
    # label17 = Label(master=frame, text="Hello17")
    # label17.pack(anchor="w")
    # label18 = Label(master=frame, text="Hello18")
    # label18.pack(before=label17)
    # label19 = Label(master=frame, text="Hello19")
    # label19.pack(after=label18)
    # 加载图片
    # img = PhotoImage(file="icon.png")  # 替换为你的图片路径
    # # 创建Label来显示图片
    # label_img = Label(master=frame, image=img)
    # label_img.pack(expand=True)
    # label = Label(master=frame,  text="center")
    # label.pack(anchor="center", expand=True)
    # label = Label(master=frame,  text="n")
    # label.pack(anchor="n", expand=True)
    # label = Label(master=frame, text="ne")
    # label.pack(anchor="ne", expand=True)
    # label = Label(master=frame,  text="e")
    # label.pack(anchor="e", expand=True)
    # label = Label(master=frame, text="se")
    # label.pack(anchor="se", expand=True)
    # label = Label(master=frame, text="s")
    # label.pack(anchor="s", expand=True)
    # label = Label(master=frame, text="sw")
    # label.pack(anchor="sw", expand=True)
    # label.pack(anchor="w", expand=True)
    # label = Label(master=frame, text="nw")
    # label.pack(anchor="nw", expand=True)

    # label = Label(master=frame,  text="center")
    # label.pack(anchor="center", expand=True)
    # label = Label(master=frame,  text="n")
    # label.pack(anchor="n", expand=True)
    # label = Label(master=frame, text="ne")
    # label.pack(anchor="ne", expand=True)
    # label = Label(master=frame,  text="e")
    # label.pack(anchor="e", expand=True)
    # label = Label(master=frame, text="se")
    # label.pack(anchor="se", expand=True)
    # label = Label(master=frame, text="s")
    # label.pack(anchor="s", expand=True)
    # label = Label(master=frame, text="sw")
    # label.pack(anchor="sw", expand=True)
    # label.pack(anchor="w", expand=True)
    # label = Label(master=frame, text="nw")
    # label.pack(anchor="nw", expand=True)
    #
    # label = Label(master=frame,  text="0行0列")
    # label.grid(row=0, column=0, pady=5, padx=5)
    # label = Label(master=frame,  text="0行1列")
    # label.grid(row=0, column=1, pady=5, padx=5)
    # label = Label(master=frame,  text="1行0列")
    # label.grid(row=1, column=0, pady=5, padx=5)
    # label = Label(master=frame,  text="1行1列")
    # label.grid(row=1, column=1, pady=5, padx=5)
    #
    # label = Label(master=frame,  text="2行0列")
    # label.grid(row=2, rowspan=2, column=0, pady=5, padx=5, sticky="nsew")
    # label = Label(master=frame, text="3行1列")
    # label.grid(row=3, column=1, pady=5, padx=5)
    #
    # label = Label(master=frame,  text="2行1列")
    # label.grid(row=2, column=1, columnspan=3, pady=5, padx=5, sticky="nsew")
    # label = Label(master=frame, text="3行2列")
    # label.grid(row=3, column=2, pady=5, padx=5)
    # label = Label(master=frame, text="3行3列")
    # label.grid(row=3, column=3, pady=5, padx=5)
    #
    # label = Label(master=frame, text="4行0列")
    # label.grid(row=4, column=0, pady=5, padx=5)
    # label = Label(master=frame, text="4行1列")
    # label.grid(row=4, column=1, pady=5, padx=5)
    #
    # label = Label(master=frame, text="100-100")
    # label.place(x=100, y=100)
    # label = Label(master=frame,  text="150-150")
    # label.place(x=150, y= 150)
    #
    # label = Label(master=frame, text="0.5-0.5")
    # label.place(relx=0.5, rely=0.5)
    # label = Label(master=frame, text="0.3-0.7")
    # label.place(relx=0.3, rely=0.7)
    #
    # label = Label(master=frame, text="100% - 40%")
    # label.place(x=220, y=10, width="100p", height="40p")
    # label = Label(master=frame, text="50px-80px")
    # label.place(x=220, y=80, height=50, width=80)
    #
    # label = Label(master=frame, text="0.3-0.2")
    # label.place(x=200, y=230, relwidth=0.3, relheight=0.2)

    # l_frame = LabelFrame(master=main_window, text="LabelFrame", width=100, height=50)
    # l_frame.pack()
    #
    # l_frame = LabelFrame(master=main_window, text="LabelFrame", width=100, height=50, bg="#8B795E")
    # l_frame.pack()
    #
    # l_frame = LabelFrame(master=main_window, text="LabelFrame", width=100, height=50, bd=5)
    # l_frame.pack()
    #
    # l_frame = LabelFrame(master=main_window, text="LabelFrame", width=100, height=50, cursor="heart")
    # l_frame.pack()
    #
    # l_frame = LabelFrame(master=main_window, text="LabelFrame", width=100, height=50, labelanchor="e")
    # l_frame.pack()
    #
    # l_frame = LabelFrame(master=main_window, text="LabelFrame", width=100, height=50, relief="raised")
    # l_frame.pack()

    # button = Button(master=main_window, text="Button", activebackground="#7A67EE", activeforeground="#EE00EE")
    # button.pack()
    #
    # button = Button(master=main_window, text="Button", highlightbackground="#7A67EE", highlightcolor="#EE00EE")
    # button.pack()
    #
    # img = PhotoImage(file="icon.png")
    #
    # button = Button(master=main_window, text="Button", image=img)
    # button.pack()
    #
    #
    # button = Button(master=main_window, text="Button", justify="right")
    # button.pack()
    #
    # button = Button(master=main_window, text="Button", relief="sunken")
    # button.pack()
    #
    # count = 0
    # def button_click():
    #     global count
    #     count += 1
    #     return count
    # # 不会改变文本
    # button = Button(master=main_window, text=f"点击了{count}次", command=button_click)
    # button.pack()
    #
    # intValue = IntVar()
    # def button2_click():
    #     global strValue
    #     intValue.set(intValue.get() + 1)
    #     return intValue
    # # 改变文本
    # button = Button(master=main_window, textvariable=intValue, command=button2_click)
    # button.pack()
    #
    # button = Button(master=main_window, text="Button" , command=button_click,state="disabled")
    # button.pack()
    #
    # button = Button(master=main_window, text="Button" , underline=2)
    # button.pack()
    #
    # def flash():
    #     button.flash()
    # button = Button(master=main_window, text="Button", activebackground="red", command=flash)
    # button.pack()
    # button.flash()

    # entry = Entry(master=main_window, show="***")
    # entry.pack()
    #
    # entry = Entry(master=main_window, state="disabled")
    # entry.pack()
    #
    # value = IntVar()
    #
    # entry = Entry(master=main_window, textvariable=value)
    # entry.pack()
    # value.set(10)
    #
    # entry = Entry(master=main_window, cursor="man")
    # entry.pack()

    # text = Text(master=main_window, state="disabled", height=5)
    # text.pack()
    #
    # text = Text(master=main_window, wrap="word", height=5)
    # text.pack()
    #
    # text = Text(master=main_window, exportselection=False, height=5)
    # text.pack()
    #
    #
    # text = Text(master=main_window, selectforeground="red", selectbackground="blue", height=5)
    # text.pack()
    # value = StringVar()
    # value.set("var1 var2 var3 var1 var2 var3 var1 var2 var3 var1 var2 var3")
    # text = Listbox(master=main_window, listvariable= value, activestyle="underline", height=5)
    # text.pack()
    #
    # text = Listbox(master=main_window, listvariable= value, selectforeground="red", selectbackground="blue", height=5)
    # text.pack()
    #
    # text = Listbox(master=main_window, listvariable= value, selectmode="multiple", height=5)
    # text.pack()

    # # 创建一个Tkinter变量来存储所选选项的值
    # selected_option = IntVar()
    #
    # # 定义选项的值和文本标签
    # options = [
    #     ("Option 1", 1),
    #     ("Option 2", 2),
    #     ("Option 3", 3),
    #     ("Option 4", 4)
    # ]
    #
    # # 创建并放置Radiobutton选项
    # for text, value in options:
    #     radiobutton = Radiobutton(main_window, text=text, variable=selected_option, value=value)
    #     radiobutton.pack(anchor="w")
    #
    # for text, value in options:
    #     radiobutton = Radiobutton(main_window, text=text, variable=selected_option, indicatoron = False, value=value)
    #     radiobutton.pack(anchor="w")

    # # 创建一个Tkinter变量来存储所选选项的值
    # option_vars = [(IntVar(value=i), f"选项{i}") for i in range(5)]
    #
    # for value, option  in option_vars:
    #     # 创建并放置Checkbutton选项
    #     checkbutton1 = Checkbutton(master=main_window, text=option, variable=value, onvalue=1, offvalue=0)
    #     checkbutton1.pack()

    # def dummy_command():
    #     print("This is a dummy command.")
    #
    # # 创建菜单栏
    # menubar = Menu(master=main_window)
    #
    # # 创建文件菜单
    # file_menu = Menu(menubar, tearoff=False)
    # file_menu.add_command(label="New", command=dummy_command)
    # file_menu.add_command(label="Open", command=dummy_command)
    # file_menu.add_command(label="Save", command=dummy_command)
    # file_menu.add_separator()
    # file_menu.add_command(label="Exit", command=main_window.quit)
    #
    # # 创建编辑菜单
    # edit_menu = Menu(menubar, tearoff=False)
    # edit_menu.add_command(label="Cut", command=dummy_command)
    # edit_menu.add_command(label="Copy", command=dummy_command)
    # edit_menu.add_command(label="Paste", command=dummy_command)
    #
    # # 将文件和编辑菜单添加到菜单栏
    # menubar.add_cascade(label="File", menu=file_menu)
    # menubar.add_cascade(label="Edit", menu=edit_menu)
    #
    # # 将菜单栏配置到主窗口
    # main_window.config(menu=menubar)

    # def dummy_command():
    #     print("This is a dummy command.")
    #
    # # 创建一个Menubutton
    # mb = Menubutton(master=main_window, text="Options")
    # mb.pack(padx=20, pady=20)
    #
    # # 创建一个菜单，关联到Menubutton
    # menu = Menu(mb, tearoff=False)
    # menu.add_command(label="Option 1", command=dummy_command)
    # menu.add_command(label="Option 2", command=dummy_command)
    # menu.add_separator()
    # menu.add_command(label="Exit", command=main_window.quit)
    #
    # # 将菜单配置到Menubutton
    # mb.config(menu=menu)

    # # 创建一个Message小部件
    # msg = Message(master=main_window,
    #                  text="This is a Message widget example",
    #                  width=200)
    #
    # # 设置Message的文本对齐方式
    # msg.config(justify=CENTER)
    #
    # # 将Message小部件放置到窗口中
    # msg.pack(padx=20, pady=20)

    # scale = Scale(master=main_window, from_=0, to=100, label="滑动条示例", orient="horizontal", tickinterval=10)
    # scale.pack(fill="x")
    # 
    # scale = Scale(master=main_window, from_=0, to=100, label="滑动条示例", orient="vertical", tickinterval=100)
    # scale.pack(fill="y", pady=10)

    # # 创建一个 Text 组件，允许垂直滚动
    #
    # text_area = Text(main_window, wrap="word", height=20, width=60)
    # text_area.pack(padx=10, pady=10, fill="both", side="left")
    #
    # # 创建一个垂直滚动条，并关联到 Text 组件
    # scrollbar = Scrollbar(master=main_window, orient="vertical", command=text_area.yview)
    # scrollbar.pack(side="right", fill="y")
    #
    # # 将滚动条与 Text 组件关联起来
    # text_area.config(yscrollcommand=scrollbar.set)
    #
    # # 插入一些示例文本到 Text 组件中
    # example_text = "这是一个示例文本框，用于演示滚动条的使用。\n" * 80
    # text_area.insert(END, example_text)

    # def open_new_window():
    #     new_window = Toplevel()
    #     new_window.title("新窗口")
    #     new_window.geometry("300x200+200+200")
    #     new_window.config(bg="light blue", bd=10, relief=RIDGE)
    #
    #     label = Label(new_window, text="这是一个新窗口！")
    #     label.pack(padx=20, pady=20)
    #
    #     button_close = Button(new_window, text="关闭", command=new_window.destroy)
    #     button_close.pack()
    #
    #
    # button_open = Button(master=main_window, text="打开新窗口", command=open_new_window)
    # button_open.pack(pady=50)
    #
    # def show_value():
    #     value = spinbox_var.get()
    #     print(f"当前选择的值是：{value}")
    #
    # spinbox_var = StringVar()
    # spinbox = Spinbox(master=main_window, from_=0, to=10, width=5, textvariable=spinbox_var, command=show_value)
    # spinbox.pack(pady=20)
    #
    # spinbox_var2 = StringVar()
    # spinbox = Spinbox(master=main_window, from_=0, to=100, width=100, textvariable=spinbox_var2, command=show_value)
    # spinbox.pack(pady=20)

    # # 创建一个水平方向的PanedWindow
    # paned_window = PanedWindow(master=main_window, orient=HORIZONTAL, sashwidth=5, sashrelief=RAISED)
    # paned_window.pack(fill=BOTH, expand=True)
    #
    # # 添加两个子窗格
    # left_frame = Frame(paned_window, bg="light blue", width=100, height=200)
    # paned_window.add(left_frame)
    #
    # right_frame = Frame(paned_window, bg="light green", width=200, height=200)
    # paned_window.add(right_frame)

    # # 创建一个画布
    # canvas = Canvas(master=main_window, bg="white", width=400, height=300, bd=2, relief=SUNKEN)
    # canvas.pack()
    #
    # # 绘制一个矩形
    # rect = canvas.create_rectangle(50, 50, 150, 100, fill="blue")
    #
    # # 绘制一个椭圆
    # oval = canvas.create_oval(200, 50, 300, 100, fill="red")

    from tkinter import ttk


    # def on_select(event):
    #     selected_value.set(combobox.get())
    #     print(f"Selected: {selected_value.get()}")
    #
    # # 创建一个变量来存储选定的值
    # selected_value = StringVar()
    #
    # # 创建一个Combobox部件
    # combobox = ttk.Combobox(master=main_window, textvariable=selected_value, width=20, state='readonly')
    # combobox['values'] = ('Option 1', 'Option 2', 'Option 3', 'Option 4')
    # combobox.pack(side="left",expand=True)
    # combobox.current(0)  # 设置默认选中第一个选项
    #
    # # 添加一个事件绑定，当选项改变时触发
    # combobox.bind("<<ComboboxSelected>>", on_select)
    #
    # # 显示选中的值的标签
    # selected_label = ttk.Label(master=main_window, textvariable=selected_value)
    # selected_label.pack(side="right")

    # # 创建Treeview部件
    #     # tree = ttk.Treeview(master=main_window, columns=('Name', 'Age', 'Gender'), show='headings')
    #     #
    #     # # 设置列名和列宽
    #     # tree.heading('Name', text='Name')
    #     # tree.heading('Age', text='Age')
    #     # tree.heading('Gender', text='Gender')
    #     #
    #     # tree.column('Name', width=100)
    #     # tree.column('Age', width=50)
    #     # tree.column('Gender', width=50)
    #     #
    #     # # 插入数据
    #     # tree.insert('', 'end', values=('John Doe', 30, 'Male'))
    #     # tree.insert('', 'end', values=('Jane Smith', 25, 'Female'))
    #     # tree.insert('', 'end', values=('Bob Brown', 40, 'Male'))
    #     #
    #     # # 显示Treeview
    #     # tree.pack(expand=True, fill=BOTH)

    # # 创建Treeview部件
    # tree = ttk.Treeview(master=main_window, columns=('Type', 'Size'), selectmode='browse')
    #
    # # 设置列名和列宽
    # tree.heading('#0', text='Name')
    # tree.heading('Type', text='Type')
    # tree.heading('Size', text='Size')
    #
    # tree.column('#0', width=150)
    # tree.column('Type', width=100)
    # tree.column('Size', width=100)
    #
    # # 插入数据
    # # 插入根节点
    # folder1 = tree.insert('', 'end', 'folder1', text='Folder 1', values=('Folder', ''))
    # folder2 = tree.insert('', 'end', 'folder2', text='Folder 2', values=('Folder', ''))
    #
    # # 插入子节点
    # file1 = tree.insert(folder1, 'end', 'file1', text='File 1', values=('File', '10 KB'))
    # file2 = tree.insert(folder1, 'end', 'file2', text='File 2', values=('File', '20 KB'))
    # subfolder = tree.insert(folder1, 'end', 'subfolder', text='Subfolder', values=('Folder', ''))
    #
    # # 插入子节点
    # file3 = tree.insert(subfolder, 'end', 'file3', text='File 3', values=('File', '15 KB'))
    #
    # # 插入子节点
    # file4 = tree.insert(folder2, 'end', 'file4', text='File 4', values=('File', '5 KB'))
    #
    # # 选中第一个根节点
    # tree.selection_set('folder1')
    #
    # # 显示Treeview
    # tree.pack(expand=True, fill=BOTH)

    # def simulate_progress():
    #     progress_bar['value'] += 10
    #     if progress_bar['value'] < 100:
    #         main_window.after(500, simulate_progress)
    #
    #
    # # 创建Progressbar部件
    # progress_bar = ttk.Progressbar(master=main_window, orient='horizontal', length=300, mode='determinate')
    #
    # # 设置进度条的样式和长度
    # progress_bar.pack(pady=20)
    #
    # # 模拟进度
    # start_button = ttk.Button(master=main_window, text="Start Progress", command=simulate_progress)
    # start_button.pack()
    #
    # # 创建 Notebook 部件
    # notebook = ttk.Notebook(master=main_window)
    #
    # # 创建第一个选项卡
    # tab1 = ttk.Frame(notebook)
    # notebook.add(tab1, text='Tab 1')
    #
    # # 在第一个选项卡中添加一些内容
    # label1 = ttk.Label(tab1, text="This is Tab 1")
    # label1.pack(padx=20, pady=20)
    #
    # # 创建第二个选项卡
    # tab2 = ttk.Frame(notebook)
    # notebook.add(tab2, text='Tab 2')
    #
    # # 在第二个选项卡中添加一些内容
    # label2 = ttk.Label(tab2, text="This is Tab 2")
    # label2.pack(padx=20, pady=20)
    #
    # # 将 Notebook 放置到主窗口中
    # notebook.pack(expand=True, fill=BOTH)
    # 创建一个水平分隔符
    # horizontal_sep = ttk.Separator(master=main_window, orient='horizontal')
    # horizontal_sep.pack(fill='x', padx=5, pady=10, side="top")
    #
    # # 创建一个垂直分隔符
    # vertical_sep = ttk.Separator(master=main_window, orient='vertical')
    # vertical_sep.pack(fill='y', padx=10, pady=5, side="right")

    # 创建一个 StringVar 变量对象
    selected_option = StringVar()

    # 设置初始值

    optionList = ('train', 'plane', 'boat','2345','234567')
    selected_option.set(optionList[0])
    # 创建 OptionMenu
    option_menu = ttk.OptionMenu(main_window, selected_option, *optionList)
    option_menu.pack(padx=20, pady=20)

    main_window.mainloop()




